/* 该文件存放web和pc端的交互方法*/

import EquipmentDetialParameteJson from "@/datas/EquipmentDetialParameters.json";
import LibraryDataJson from "@/datas/EquipmentLibraryData.json";
import { ref } from "vue";

/**
 * 发送消息至pc端获取某一设备类型的设备库的信息
 * @param {*} filterVal 筛选的设备类型，比如电压器
 * @param {*} backVal 返回的设备库的信息
 */
export function sendMsgToGetEquipmentLibrary(filterVal, backVal) {
  console.log("sendMsgToGetEquipmentLibrary: ", filterVal);
  if (window.sendMsgToGetEquipmentLibrary) {
    window.sendMsgToGetEquipmentLibrary(filterVal, backVal);
  } else {
    const i = ref(0);
    const dataTemp = ref([]);
    for (i.value = 0; i.value < LibraryDataJson.length; i.value++) {
      if (LibraryDataJson[i.value].name == filterVal.value) {
        dataTemp.value = LibraryDataJson[i.value].data;
      }
    }
    backVal.value = dataTemp;
    console.log("sendMsgToGetEquipmentLibrary:测试数据", dataTemp);
  }
}

/**
 * 发送信息至pc段获取某一设备的详细新设
 * @param {*} equipmentModel 设备型号
 * @param {*} backValOne 有关该设备的碳排放因子的信息
 * @param {*} backValTwo 该设备本身的详细信息
 */
export function sendMsgToGetEquipmentCarbonFactorInfor(
  equipmentModel,
  backValOne,
  backValTwo
) {
  console.log("sendMsgToGetEquipmentCarbonFactorInfor:开始");
  if (window.sendMsgToGetEquipmentCarbonFactorInfor) {
    window.sendMsgToGetEquipmentCarbonFactorInfor(equipmentModel, backVal);
  } else {
    const tempCarData = ref([]);
    const tempShowData = ref([]);
    console.log("sendMsgToGetEquipmentCarbonFactorInfor:测试数据");
    const i = ref(0);
    for (i.value = 0; i.value < EquipmentDetialParameteJson.length; i.value++) {
      if (EquipmentDetialParameteJson[i.value].name == equipmentModel) {
        tempCarData.value = EquipmentDetialParameteJson[i.value].carbons;
        tempShowData.value = EquipmentDetialParameteJson[i.value].data;
      }
    }

    backValOne.value = tempCarData.value;

    for (var j = 0; j < tempShowData.value.length; j++) {
      const tem = tempShowData.value[j].value;
      backValTwo.value.push(tem);
    }
  }
  console.log("sendMsgToGetEquipmentCarbonFactorInfor:结束");
}

/**
 * 发送msg至pc端-应用
 * @param {*} param 结果
 */
export function sendMsgToApply(param) {
  console.log("sendMsgToApply : 开始");
  if (window.sendMsgToApply) {
    window.sendMsgToApply;
  } else console.log("sendMsgToApply : 失败结束");
}

/**
 * 发送msg至pc端-取消
 * @param {*} param
 */
export function sendMsgToCancle(param) {
  console.log("sendMsgToCancle : 开始");
  if (window.sendMsgToCancle) {
    window.sendMsgToCancle;
  } else console.log("sendMsgToCancle : 失败结束");
}

/**
 * 发送msg至pc端-导出
 * @param {*} param
 */
export function sendMsgToExport(param) {
  console.log("sendMsgToExport : 开始");
  if (window.sendMsgToExport) {
    window.sendMsgToExport;
  } else console.log("sendMsgToExport : 失败结束");
}

/**
 * 发送msg至pc端-导入
 * @param {*} param
 */
export function sendMsgToImport(param) {
  console.log("sendMsgToImport : 开始");
  if (window.sendMsgToImport) {
    window.sendMsgToImport;
  } else console.log("sendMsgToImport : 失败结束");
}
